package com.itzhigui.utils;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

import java.io.Serializable;

/**
 * 统一返回给前端的工具类
 */


 @Data  //生成set和get方法
 @NoArgsConstructor //生成默认构造方法
 @AllArgsConstructor// 生成全参构造方法
 @ToString //重写toString方法
public class ResponseUtil implements Serializable {
     private Integer code;
     private String msg;
     private Object data;

    /**
     * 带有数据的状态
     * @param responseEnum
     * @param obj
     * @return
     */
     public static ResponseUtil get(ResponseEnum responseEnum,Object obj){
         return new ResponseUtil(responseEnum.getCode(), responseEnum.getMsg(), obj);
     }

    /**
     * 不带有数据的状态
     * @param responseEnum
     * @return
     */
    public static ResponseUtil get(ResponseEnum responseEnum){
        return new ResponseUtil(responseEnum.getCode(), responseEnum.getMsg(), null);
    }
}
